package com.example.firstjavamqtt.factory.strategy.callback;

import com.alibaba.fastjson.JSONObject;
import com.example.firstjavamqtt.model.dto.mqtt.MqttInfraredDto;
import com.example.firstjavamqtt.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class HandleInfraredMsgStrategy implements HandleMessageStrategy{

    private static RedisUtil redisUtil;

    @Override
    public void handle(String msg) {
        MqttInfraredDto mqttInfraredDto = JSONObject.parseObject(msg, MqttInfraredDto.class);
        mqttInfraredDto.setOperationDate(new Date());
        redisUtil.lSet("Infrared:" + mqttInfraredDto.getDeviceId(),mqttInfraredDto);
        System.out.println("红外检测存取完成");
    }

    @Autowired
    public void setRedisUtil(RedisUtil redisUtil) {
        HandleInfraredMsgStrategy.redisUtil = redisUtil;
    }

}
